#!/bin/bash
if [[ $# -ne 2 ]]; then
    echo "The format is as follows:"
    echo "bash autodock-4.2.6.sh buildpath installpath"
    echo ":param buildpath: 应用构建绝对路径"
    echo ":param installpath: 应用安装绝对路径"
    exit 1
fi

[[ ! "$1" =~ ^/.* || ! -d "$1" || "$1" = "/" ]] &&  echo "请输入正确的构建路径" && exit 1
[[ ! "$2" =~ ^/.* || ! -d "$2" || "$2" = "/" ]] &&  echo "请输入正确的安装路径" && exit 1
[[ "$1" = "$2" ]] && echo "构建路径与安装路径不能相同" && exit 1
buildpath=$1
installpath=$2
[[ "$buildpath" =~ .*/$ ]] && buildpath=${buildpath%/*}
[[ "$installpath" =~ .*/$ ]] && installpath=${installpath%/*}
echo "运行环境"
yum install -y  environment-modules csh time  gcc gcc-c++ automake autoconf  make systemd-devel  wget tar 
echo "下载安装包"
set -e
wget -t 10 -c -P $buildpath https://autodock.scripps.edu/wp-content/uploads/sites/56/2021/10/autodocksuite-4.2.6-src.tar.gz
tar xf $buildpath/autodocksuite-4.2.6-src.tar.gz -C $buildpath && mv $buildpath/src $buildpath/autodocksuite-4.2.6
rm -rf $buildpath/autodocksuite-4.2.6-src.tar.gz

echo "安装autodock4"
cd $buildpath/autodocksuite-4.2.6/autodock
CC=clang CXX=clang++ CFLAGS="-march=armv8.2-a -fsigned-char -ffp-contract=off" CXXFLAGS="-march=armv8.2-a -fsigned-char -ffp-contract=off"  ./configure --prefix=$installpath/autodock-4.2.6
make 
make install
echo "安装autogrid"
cd $buildpath/autodocksuite-4.2.6/autogrid
CC=clang CXX=clang++ CFLAGS="-march=armv8.2-a -fsigned-char -ffp-contract=off" CXXFLAGS="-march=armv8.2-a -fsigned-char -ffp-contract=off"  ./configure --prefix=$installpath/autodock-4.2.6
make
make install 
echo "配置环境变量"
cat>"$installpath/autodock-4.2.6/autodock_modulefiles"<<EOF
#%Module1.0
conflict autodock
variable modfile [file normalize [info script]]
proc getModulefileDir {} {
    variable modfile
    set modfile_path [file dirname \$modfile]
    return \$modfile_path
}
set pwd [getModulefileDir]
set autodock \$pwd
setenv autodock \$autodock
prepend-path PATH \$autodock/bin
EOF
cp -r $buildpath/autodocksuite-4.2.6/autodock/EXAMPLES/ $installpath/autodock-4.2.6/

